package com.zhuoshi.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.zhuoshi.bean.SpareBean;
import com.zhuoshi.utils.DbHelper;

/**
 * 备件管理查询 数据处理层
 * @author Administrator
 *
 */
public class SpareDao {
	public List<SpareBean> getList(){
		Connection conn = null;
		PreparedStatement pstat = null;
		ResultSet rs = null;
		List<SpareBean> list = new ArrayList<SpareBean>();
		try {
			conn = DbHelper.getConnection();
			StringBuffer sql = new StringBuffer();
			sql.append("select c.numerical as numerical,c.sqarename as sqarename,c.modeltype as modeltype,p.supplier from contractsub c LEFT JOIN purchase p on c.sqarename=p.sqarename");
			pstat = conn.prepareStatement(sql.toString());
			rs = pstat.executeQuery();
			while(rs.next()){
				SpareBean bean = new SpareBean();
				bean.setNumerical(rs.getInt("numerical"));
				bean.setModeltype(rs.getString("modeltype"));
				bean.setSqarename(rs.getString("sqarename"));
				bean.setSupplier(rs.getString("supplier"));
				Integer customerid = new ContractMasterDao().getContractMasterBean(rs.getInt("numerical")).getCustomerid();
				String custname = new CustomerDao().getModel(customerid).getCustname();
				bean.setCustname(custname);
				list.add(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DbHelper.dispose(conn, pstat, rs);
		}
		
		return list;
		
	}
}
